const bcrypt = require('bcryptjs')

module.exports = {
    toInt(str) {
        if (typeof str === 'number') return str;
        if (!str) return str;
        return parseInt(str, 10) || 0;
    },
    encrypt(password) {
        let salt = bcrypt.genSaltSync(5);
        let hash = bcrypt.hashSync(password, salt);
        return hash;
    },
    decrypt(password, hash) {
        return bcrypt.compareSync(password, hash)
    }
}